package cn.lingyangwl.agile.auth;

import cn.lingyangwl.agile.auth.gituser.GitUserProperties;
import cn.lingyangwl.agile.model.constants.ModuleCons;
import cn.lingyangwl.framework.cache.redis.config.FastJson2JsonRedisSerializer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.context.SecurityContextHolder;

import javax.annotation.PostConstruct;

/**
 * @author shenguangyang
 */
@Configuration
@EnableConfigurationProperties(GitUserProperties.class)
@MapperScan(basePackages = ModuleCons.SCAN_BASE_PACKAGE + ".auth.mapper")
public class AuthMainConfig {
    @PostConstruct
    public void init() {
        FastJson2JsonRedisSerializer.addDeserializeAutoTypeFilter(
                "org.springframework.security.authentication.UsernamePasswordAuthenticationToken",
                "org.springframework.security.oauth2.server.authorization.OAuth2Authorization",
                "org.springframework.security.core.authority.SimpleGrantedAuthority"
        );
        // 存储策略 MODE_INHERITABLETHREADLOCAL 就支持在子线程中获取当前登录用户信息
        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    }
}
